/**
 * @Date: Apr 22, 2010 12:31:57 PM
 */
package com.philip.journal.common;

import com.philip.journal.core.Messages.Error;

/**
 * @author cry30
 */
public final class XmlUtils {

    /** Singleton instance reference. */
    private static final XmlUtils INSTANCE = new XmlUtils();

    /** Prevent direct instantiation of this class. */
    private XmlUtils() {}

    /**
     * Factory method.
     *
     * @return Singleton instance of this class.
     */
    public static XmlUtils getInstance() {
        return INSTANCE;
    }

    /** Array of CData literals. */
    public static final String[] CDATA_LITERALS = {
            "\n",
            "&",
            ">",
            "<" };

    /**
     * Utility method to check for xml escapable characters.
     *
     * @param data the text to check if CDATA will be required.
     * @return - true only if data requires the use of CDATA. throws IllegalArgumentException when the data
     *         param is null.
     */
    public static boolean isCData(final String data) {
        if (data == null) {
            throw new IllegalArgumentException(Error.IAE_NULL);
        }
        boolean retval = false;
        for (final String cdata : CDATA_LITERALS) {
            if (data.indexOf(cdata) > -1) {
                retval = true;
                break;
            }
        }
        return retval;
    }
}
